/**
 * 获取资源(菜单+权限)树形列表
 */
import {MenuFormData, MenuItem, Resource} from "@/types/system/menu";
import request from "@/utils/request";
import {AxiosPromise} from "axios";
import {Option} from "@/types/common";


export function listResources(): AxiosPromise<Resource[]> {
  return request({
    url: '/menu/listResources',
    method: 'get',
  });
}

export function listByQuery(): AxiosPromise<MenuItem[]> {
  return request({
    url: '/menu/listByQuery',
    method: 'get',
  });
}
export function listByCurrUser(): AxiosPromise<MenuItem[]> {
  return request({
    url: '/menu/listByCurrUser',
    method: 'get',
  });
}

export function listMenuOptions(): AxiosPromise<Option[]> {
  return request({
    url: '/menu/listMenuOptions',
    method: 'get',
  });
}


/**
 * 获取菜单详情
 * @param id
 */
export function getMenuDetail(id: string): AxiosPromise<MenuFormData> {
  return request({
    url: '/menu/details/' + id,
    method: 'get',
  });
}

/**
 * 添加菜单
 *
 * @param data
 */
export function addMenu(data: MenuFormData) {
  return request({
    url: '/menu/add',
    method: 'post',
    data: data,
  });
}

/**
 * 修改菜单
 *
 * @param id
 * @param data
 */
export function updateMenu(id: string, data: MenuFormData) {
  return request({
    url: '/menu/updateById/' + id,
    method: 'put',
    data: data,
  });
}

/**
 * 删除菜单
 *
 * @param id
 */
export function deleteMenu(id: string) {
  return request({
    url: '/menu/delete/' + id,
    method: 'delete',
  });
}
